package com.zyh.dao.impl;

import com.zyh.dao.IBrandDao;
import com.zyh.domain.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

/**
 * @author cyrus
 */
@Repository
public class BrandDaoImpl implements IBrandDao {

    private final JdbcTemplate jdbcTemplate;

    public BrandDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Brand> findAll() {
        List<Brand> brands = jdbcTemplate.query("select * from tb_brand", new BeanPropertyRowMapper<Brand>(Brand.class));
        return brands;
    }
}
